using System;
using DirkRettschlag.Utils;


namespace Departure
{
    public class GeneralSettings
    {

        #region Variables

        Settings settings;
        string stations;
        bool autoUpdate;
        double updateInterval;
        bool useWebService;
        bool autoConnect;
        string hTTPHeader;
        string userAgent;
        bool removePastDepartures;
        string countdownTrainFormat;
        string deviceID = Utilities.GetDeviceID();
        string webServiceURL;
        
        #endregion Variables

        #region Properties

        public string Stations
        {
            get { return this.stations; }
            set { this.stations = value; }
        }

        public bool AutoUpdate
        {
            get { return this.autoUpdate; }
            set { this.autoUpdate = value; }
        }

        public double UpdateInterval
        {
            get { return this.updateInterval; }
            set { this.updateInterval = value; }
        }

        public bool UseWebService
        {
            get { return this.useWebService; }
            set { this.useWebService = value; }
        }

        public bool AutoConnect
        {
            get { return this.autoConnect; }
            set { this.autoConnect = value; }
        }

        public string HTTPHeader
        {
            get { return this.hTTPHeader; }
            set { this.hTTPHeader = value; }
        }

        public string UserAgent
        {
            get { return this.userAgent; }
            set { this.userAgent = value; }
        }

        public bool RemovePastDepartures
        {
            get { return this.removePastDepartures; }
            set { this.removePastDepartures = value; }
        }

        public string CountdownTrainFormat
        {
            get { return this.countdownTrainFormat; }
            set { this.countdownTrainFormat = value; }
        }

        public string DeviceID
        {
            get { return this.deviceID; }
        }

        public string WebServiceURL
        {
            get { return this.webServiceURL; }
            set { this.webServiceURL = value; }
        }

        #endregion Properties

        #region Public Methods

        public void saveSettings()
        {
            settings = new Settings(Utilities.AppPath() + "\\settings.xml");

            settings.WriteString("Main", "Stations", stations);
            settings.WriteBool("Main", "AutoUpdate", autoUpdate);
            settings.WriteDouble("Main", "UpdateInterval", updateInterval);
            settings.WriteBool("Main", "UseWebService", useWebService);
            settings.WriteBool("Main", "AutoConnect", autoConnect);
            settings.WriteString("Main", "HTTPHeader", hTTPHeader);
            settings.WriteString("Main", "UserAgent", userAgent);
            settings.WriteBool("Main", "RemovePastDepartures", removePastDepartures);
            settings.WriteString("Main", "CountdownTrainFormat", countdownTrainFormat);
            settings.WriteString("Main", "WebServiceURL", webServiceURL);

            settings.Save();

        }
        
        public void getSettings()
        {

            settings = new Settings(Utilities.AppPath() + "\\settings.xml");

            stations = settings.ReadString("Main", "Stations", "");
            autoUpdate = settings.ReadBool("Main", "AutoUpdate", false);
            updateInterval = settings.ReadDouble("Main", "UpdateInterval", 10);
            useWebService = settings.ReadBool("Main", "UseWebService", false);
            autoConnect = settings.ReadBool("Main", "AutoConnect", false);
            hTTPHeader = settings.ReadString("Main", "HTTPHeader", "");
            userAgent = settings.ReadString("Main", "UserAgent", "");
            removePastDepartures = settings.ReadBool("Main", "RemovePastDepartures", false);
            countdownTrainFormat = settings.ReadString("Main", "CountdownTrainFormat", "%TR% - %DI%");
            webServiceURL = settings.ReadString("Main", "WebServiceURL", "http://");

        }

        #endregion Public Methods

    }
}
